<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css" />
<jsp:include page="../inc.jsp"></jsp:include>

<meta http-equiv="X-UA-Compatible" content="edge" />
<title>收款计算-审核</title>
<style>
        .payInformartion{
			width:1100px;
            height:40px;
            background: #3989c8;
        }
        .payInformartion li{
           padding-left: 15px;
            width:200px;
            height:40px;
            line-height: 40px;
            font-size: 14px;
            color: white;
        } 
      #tb{
      
       	margin-top:10px;
      
        }
        #tb .headerColor{
        	color:#3989c8;
        }
   		#tb table{
   			border:1px solid #95B8E7;
   			border-collapse:collapse;
   		}
   		#tb table thead th{
   		border:1px solid #dbdbdb;
   			text-align:center;
   			font-size:12px;
   			color:#95B8E7;
   			height:30px;
   		}
   		#tb table td{
   			border:1px solid #dbdbdb;
   			text-align:center;
   			width:200px;
   			font-size:12px;
   			height:30px;
   			
   		}
</style>
<script>
	var dataGridData = {total:0, rows:[]};
	var payDataGrid;
	var payMoney="";
	var payNo="";
	//console.log(dataGridData);
	$(function(){
		payDataGrid=$("#payMent").datagrid({
			data:dataGridData,
		    fit : true,
		    singleSelect : true,
		    method : 'get',
		    showFooter: true,
		    idField:'orderNumber',
		    onClickRow: onClickRow,
		    columns:[ [ /*{
		        width : '100',
		        title : 'id',
		        align : 'center',
		        field : 'id',
		        hidden:true
		    },*/{
		        width : '160',
		        title : '平台单号',
		        align : 'center',
		        field : 'orderNumber'
		    },{
		     width : '160',
		     title : '供应商单号',
		     align : 'center',
		     field : 'pssOrderNumber'
		     },{
		        width : '150',
		        title : '供应商/采购商',
		        align : 'center',
		        field : 'act_pay',
		        formatter: function(value,row){
		        	if(row.financeStatus!=0){
		        		 return "<span>卖："+row.saleOrganName+"</span>"+"<br/>"+"<span>买："+row.buyOrganName+"</span>";
		        	}
		        }
		    },{
		        width : '150',
		        title : '订单金额/人数',
		        align : 'center',
		        field : 'act_sum',
		        formatter:function(value,row){
		        	if(row.financeStatus!=0){
		           	 	return "￥"+row.payPrice+"/"+row.purchQuantity+"人";
		        	}
		        }
		    },{
		        width : '60',
		        title : '支付金额',
		        align : 'center',
		        field : 'payMoney'
		    },{
		        width : '120',
		        title : '支付日期',
		        align : 'center',
		        field : 'payTime'
		    },{
		        width : '60',
		        title : '订单状态',
		        align : 'center',
		        field : 'orderStatus',
		        formatter: function(value,row){
		        	if(row.financeStatus!=0){
		        		switch(row.orderStatus+""){
			                case "0":
			                    return "待支付";
			                    break;
			                case "1":
			                    return "待审核";
			                    break;
			                case "2":
			                    return "待出票";
			                    break;
			                case "3":
			                    return "出票中";
			                    break;
			                case "4":
			                    return "出票成功";
			                    break;
			                case "5":
			                    return "已取消";
			                    break;
			            }
		        	}
		        }
		    },{
		        width : '60',
		        title : '财务状态',
		        align : 'center',
		        field : 'financeStatus',
		        formatter: function(value,row){
		        	if(row.financeStatus!=0){
		        		 switch(row.financeStatus+""){
				            case "1":
								return "收款待审核";
								break;
							case "2":
								return "已收款";
								break;
			            }
		        	}
		        }
		    },{
		        width : '150',
		        title : '备注',
		        align : 'center',
		        field : 'a',
		        editor:{
					type:'text'
				}
		        }
		    ] ]
		    
		});
	
		$('#payMent').datagrid('reloadFooter',[{orderNumber: '总计', payMoney: payMoney,financeStatus:0}]);
		//var footerRows=$('#payMent').datagrid('getFooterRows');
		//console.log(footerRows)
		//点击通过 
		$("#pass").click(function(){
			passOrCancle(1);
		});
		$("#cancel").click(function(){
			passOrCancle(-1);
			
		});
	}); 
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#payMent').datagrid('validateRow', editIndex)){ 
			$('#payMent').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	};
	function onClickRow(index,rowData){
		if (editIndex != index){
			if (endEditing()){
				$('#payMent').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				editIndex = index;
			} else {
				$('#payMent').datagrid('selectRow', editIndex);
			}
		}
	};
	
	//封装函数  实现点击事件的数据传输
	function passOrCancle(n){
		
		if (endEditing()){
			$('#payMent').datagrid('acceptChanges');
		}else{
			layer.alert("请填写完订单备注信息。");
			return false;
		}
		progressLoad();
		var param={};//存储所有参数
		var order=[];//存储order参数
		var rows=$("#payMent").datagrid("getRows");
		for(var i=0;i<rows.length;i++){
			order[i]={"orderNo":rows[i].orderNumber,"orderRemark":rows[i].a};
		};
		//console.log(order);
		var remark=$("#beizhu").val();
		var status=n;
		param={"order":order,"auditRemarks":remark,"payNo":payNo,"status":status};
		//发送ajax请求 
		$.ajax({
			type:"post",
			url:"${ctx}/pltmPayment/auditPayment?temp="+Math.random(),
			data:"pay="+JSON.stringify(param),
			success:function(data){
				progressClose();
				if(data.success){
					layer.alert('审核完成！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
						closeWin();
						layer.close(index);
					});
				}else{
					layer.alert("审核失败！");
				}
			},
			error:function(msg){
				progressClose();
				layer.alert("请检查您的网络连接，然后重试！");
			}
		});
	};
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	function closeWin(){
		 parent.layer.close(index);
	}
</script>
</head>
<body style="margin-left: 10px">
    <div class="orderdetail_header">
		支付单号：<span id="pssorderNumber"></span>
	</div>
	<div style="height:100px;width: 98%">
          <table id="payMent" style="height:auto"></table>
	</div>	
  
	<div id="tb">
         <table>
         	<thead>
        	<tr>
        		<td class="headerColor">账号</td>
        		<td class="headerColor">账户名称</td>
        		<td class="headerColor">线下支付</td>
        		<td class="headerColor">平台收款</td>
        		<td class="headerColor">通道费</td>
        	</tr>
        	</thead>
        	<tbody>
        		<tr>
        		<td id="payAccount"></td>
        		<td id="payName"></td>
        		<td id="payMoney"></td>
        		<td id="cashMoney"></td>
        		<td>￥00.00</td>
        		</tr>
        	</tbody>
         </table>
     </div>  
     <div style="margin-top:5px;">
      <h3>备注：</h3>
      <textarea id="beizhu" rows="5" cols="150" style="border:1px solid #95B8E7;font-size:12px;"></textarea>
     </div>
     <button id="pass" class="add_minus">通过</button>
     <button id="cancel" class="backOne">不通过</button>
</body>
<script type="text/javascript">
function fillDataGrid(){
	$.ajax({
		type:"get",
		url:"${ctx}/pltmPayment/paymentDetail?id=${id}&temp="+Math.random(),
		dataType:'json',
		async:false,
		success:function(data){
			a=data;
			dataGridData.total = data.paymentDetails.length;
			dataGridData.rows = data.paymentDetails;
			$("#pssorderNumber").text(data.payNo);
			$("#payAccount").text(data.payAccount);
			$("#payName").text(data.payName);
			$("#payMoney").text(data.payMoney);
			$("#beizhu").text(CommonConverter.toNullString(data.auditRemarks));
			$("#payNo").html(data.payNo);
			payMoney = data.payMoney;
			payNo=data.payNo;
		}
	});
}
fillDataGrid();
</script>
</html>